Module.getManifest   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 15
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
B 0 12 6
1
'use strict'
2
3
const output = require('../output')
4
const path = require('path')
5
const jsonfile = require('jsonfile')
6
const createManifest = require('./ModuleManifest')
7
8
var Module = {}
9
10
/**
11
 * Get the manifest object for the module in the current directory.
12
 * @param {function(ModuleManifest)} callback
13
 * @param {string} basePath
14
 */
15
Module.getManifest = function (callback, basePath) {
16
  var modulePath = basePath ? path.join(basePath, 'module.json') : 'module.json'
17
  jsonfile.readFile(modulePath, function (err, module) {
18
    if (err) {
19
      output.err('Error reading module.json: ' + err)
20
      return
21
    }
22
    if (!('slug' in module) || !module.slug || typeof module.slug !== 'string' || !module.slug.length) {
23
      output.err('Please set a valid value for module.slug')
24
      return
25
    }
26
27
    callback(createManifest(module))
28
  })
29
}
30
31
module.exports = Module
32